package org.yxs.es;

import org.apache.http.HttpHost;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestHighLevelClient;
import org.junit.After;
import org.junit.Before;

import java.io.IOException;
import java.util.Objects;

/**
 * @author: y-xs
 * @date: 2021/08/25 18:34
 * @description: 服务连接
 */
public class ElasticsearchTest {

    /**
     * 连接客户端【高级客户端】
     */
    private RestHighLevelClient client;

    @Before
    public void init() {
        HttpHost serverHost = new HttpHost("127.0.0.1", 9200);
        client = new RestHighLevelClient(RestClient.builder(serverHost));
    }

    @After
    public void destroy() {
        if (Objects.nonNull(client)) {
            try {
                client.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }

}
